package CollectionDemo.MapDemo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Traverse {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<String, String>();
        map.put("a","x");
        map.put("b","y");
        map.put("c","z");
        map.put("d","o");
        Set<String> keys = map.keySet();//获取map集合的key值
        map.values();//获取map集合的所有value值
        System.out.println("Map的两种遍历：");
        //遍历map集合，通过map.Keyset();
        for (String key:keys) {
            System.out.println("key:" + key + ",value:" + map.get(key));
        }
        System.out.println("-------------");
        //通过map.entrySet();
        Set<Map.Entry<String,String>> entries = map.entrySet();
        for (Map.Entry<String,String> en:entries) {
            System.out.println("key:" + en.getKey() + ",value:" + en.getValue());

        }
    }
}
